package util;

import java.sql.*;

public class JdbcUtil {
    private  static  String driver = "com.mysql.cj.jdbc.Driver";
    private  static  String url = "jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=UTF-8";
    private  static  String username = "root";
    private  static  String password = "root";
    private static Connection con = null;

    /**
     * 获取连接的数据库
     * @return
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    public static  Connection getCon() throws ClassNotFoundException, SQLException {
        Class.forName(driver);
        con = DriverManager.getConnection(url,username,password);
        return con;
    }

    /**
     * 执行关闭连接
     * @param rs
     * @param ps
     * @param con
     * @throws SQLException
     */
    public static void close(ResultSet rs, PreparedStatement ps,Connection con) throws SQLException {
        if(rs != null){
            rs.close();
        }
        if(ps != null){
            ps.close();
        }
        if(con != null){
            con.close();
        }
    }

    /**
     * 执行操作
     * @param rs
     * @param ps
     * @param con
     */
    public static void getops(ResultSet rs, PreparedStatement ps,Connection con){
        if(rs != null){

        }
        if(ps != null){

        }
        if(con != null){

        }
    }
}
